﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using EasyClassUI.forms.blog;
using EasyClassUI.entity;
using EasyClassUI.WebRequest;

namespace EasyClassUI.forms.group
{
    public partial class GroupProfile : UserControl
    {
        private StudyGroup group;
        public GroupProfile(string groupName, string groupProfile, StudyGroup group, bool JoinEnable)
        {
            InitializeComponent();
            groupNameLabel.Text = groupName;
            groupProfileTextBox.Text = groupProfile;
            this.group = group;
            JoinLabel.Enabled = JoinEnable;
            JoinLabel.Visible = JoinEnable;
        }

        private void groupNameLabel_Click(object sender, EventArgs e)
        {
            UploadButton certainGWindow = new UploadButton(group);
            certainGWindow.Show();
            
        }

        private void JoinLabel_Click(object sender, EventArgs e) {
            GroupService groupService = new GroupService();
            string result = groupService.JoinGroup(group.StudyGroupID.ToString(), User.CurrentUser.Token);
            if (result == "200") {
                User.Message.Add($"You joined group {group.StudyGroupName}");
                AddToGroup.addToGroup.setErr("Join successed!");
            }

            else {
                AddToGroup.addToGroup.setErr("Something went wrong, try to search again or check your networks.");
            }
        }
    }
}
